<?php

namespace app\models;
use yii\db\ActiveRecord;
use yii\helpers\ArrayHelper;

class Region extends ActiveRecord
{
    public function rules()
    {
        return [
            ['region_name', 'required', 'message' => '请填写区域.'],
            ['region_type_id', 'required', 'message' => '请选择类型.'],
            ['parent_region_id', 'integer'],

        ];

    }



    public function getParentRegions($parent_region_id=null)
    {
        return $this->hasOne(Region::className(), ['id' => 'parent_region_id']);
    }

    public function getCityList($parent_region_id=null)
    {
        $model = Region::find()->where(['parent_region_id' => $parent_region_id ])->orderBy('id')->all();


        return ArrayHelper::map($model, 'id', 'region_name');

    }
}

?>
